
#ifndef __ME32G030_SPI_H__
#define __ME32G030_SPI_H__


#ifdef	__cplusplus
extern "C" {	/* allow C++ to use these headers */
#endif	/* __cplusplus */

#include "me32g030.h"


#define SPI_FRAME	0
#define TI_FRAME	1
#define MICROWIRE_FRAME	2


#define 	SPI_STAT_TFE 1 	/**< TX FIFO Empty */
#define 	SPI_STAT_TNF 2	/**< TX FIFO not full */
#define 	SPI_STAT_RNE 4	/**< RX FIFO not empty */
#define 	SPI_STAT_RFF 8	/**< RX FIFO full */
#define 	SPI_STAT_BSY 0x10 /* SPI Busy */

	
#define SPI_INT_RX_FIFO_FULL				1
#define SPI_INT_RX_FIFO_NOT_EMPTY		2
#define SPI_INT_RX_FIFO_HALF_FULL		4
#define SPI_INT_TX_FIFO_HALF_EMPTY	8

#define SPI_MODE0	0
#define SPI_MODE1	1
#define SPI_MODE2	2
#define SPI_MODE3	3
	
#define SPI_MASTER	0
#define SPI_SLAVE		1


#define SPI_Set_NSS_High(spi) 					spi->CSCR_b.SWSEL=1;spi->CSCR_b.SWCS=1;
#define SPI_Reset_NSS_Low(spi) 					spi->CSCR_b.SWSEL=1;spi->CSCR_b.SWCS=0;
#define SPI_Write_FIFO(spi,data) 				spi->DAT=data;
#define SPI_Busy(spi) 									spi->STAT_b.BSY

void SPI_Open(SPI0_Type * spi,uint8_t framemode, uint8_t bitwidth, uint8_t master, uint8_t spionlymode);
void SPI_Close(SPI0_Type * spi);
void SPI_SetClk(SPI0_Type * spi,uint32_t freq);
void SPI_ClearReceiveFIFO(SPI0_Type * spi);
void SPI_SingleWriteRead(SPI0_Type * spi,uint16_t *data);
void SPI_Write (SPI0_Type * spi,uint8_t *src, uint8_t noofdata);
void SPI_Read (SPI0_Type * spi,uint8_t *dst, uint8_t noofdata);
void SPI_ClrInt(SPI0_Type * spi);
void SPI_EnableInt(SPI0_Type * spi,uint8_t inttype);

#ifdef __cplusplus
} /* allow C++ to use these headers */
#endif	/* __cplusplus */

#endif

